/**
 * Created by wanthering on 2017/8/16.
 */

const mongoose = require('mongoose')
const Schema = mongoose.Schema
const ObjectId = Schema.ObjectId

const ArticleSchema = new mongoose.Schema({
  phone:String,
  article:String,
  lesson:ObjectId,
  meta:{
    createAt:{type:Date,default:Date.now()},
    updateAt:{type:Date,default:Date.now()}
  }
});

ArticleSchema.pre('save',function(next){
  if(this.isNew){
    this.meta.createAt = this.meta.updateAt = Date.now();
  }else{
    this.meta.updateAt = Date.now();
  }
  next();
});

module.exports = mongoose.model('Article',ArticleSchema);